import 'package:flutter/material.dart';

class MyGridView extends StatelessWidget{
  List<Widget> list=[
    Container(alignment: Alignment.center,decoration: BoxDecoration(color: Colors.grey),child: Text("item"),),
    Container(alignment: Alignment.center,decoration: BoxDecoration(color: Colors.grey),child: Text("item"),),
    Container(alignment: Alignment.center,decoration: BoxDecoration(color: Colors.grey),child: Text("item"),),
    Container(alignment: Alignment.center,decoration: BoxDecoration(color: Colors.grey),child: Text("item"),),
    Container(alignment: Alignment.center,decoration: BoxDecoration(color: Colors.grey),child: Text("item"),)
  ];
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text("网格视图GridView"),
      ),
      body: GridView.builder(
        itemCount: list.length,
        itemBuilder: (BuildContext context,int index){
          return list[index];
        },
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
          mainAxisSpacing:2.0,
          crossAxisSpacing: 2.0,
          crossAxisCount: 3
        ),
      )
    );
  }
}